package cn.wolfcode.jedis;

import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public class JedisTestSorted_set {
    @Test
    public void test(){
        // 1:创建Jedis连接池
        JedisPool pool = new JedisPool("localhost", 6379);
        // 2:从连接池中获取Jedis对象
        Jedis jedis = pool.getResource();
        /*设置密码
	    jedis.auth("");*/
        // 3:TODO


        //sorted_set类型
        /*存入分数和名称
        jedis.zadd("users",2000.00,"user1");
        jedis.zadd("users",2000.00,"user2");
        jedis.zadd("users",2000.00,"user3");
        偏移名称对应的分数
        jedis.zincrby("users",2000.00,"user1");
        jedis.zincrby("users",1000.00,"user2");*/

        /*按照分数升序输出名称
        System.out.println(jedis.zrange("users", 0, -1));
        System.out.println("---------------------------------");
        按照分数降序输出名称
        System.out.println(jedis.zrevrange("users", 0, -1));
        System.out.println("---------------------------------");
        升序返回排名
        System.out.println(jedis.zrank("users", "user1"));
        System.out.println("---------------------------------");
        降序返回排名
        System.out.println(jedis.zrevrank("users", "user1"));
        System.out.println("---------------------------------");
        返回元素个数
        System.out.println(jedis.zcard("users"));*/
        // 4:关闭资源
        jedis.close();
        pool.destroy();
    }
}
